package leetcode;

import java.util.Stack;

/**
 * @param
 * @author oyz
 * @version 1.0
 * @description: 有效的括号
 * @date 2022/4/26 20:27
 */
public class Code20 {


    public static void main(String[] args) {
        boolean valid = new Code20().isValid("([])");
        System.out.println(valid);
    }


    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for(Character o:s.toCharArray()){
           if(o == '(') stack.push(')');
           else if(o == '{') stack.push('}');
           else if (o == '[') stack.push(']');
           else if (stack.isEmpty()|| o != stack.pop()) return false;
        }
        return stack.isEmpty();
    }
}
